package com.dudu.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.dudu.mapper.OrderMapper;
import com.dudu.model.vo.OrderDetailsVO;
import com.dudu.qo.OrderQo;
import com.dudu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @Author: 小河
 * @Description:
 * @Date: 2024-07-15 16:15:54
 * @Version: 1.0
 */

@Service
public class OrderServiceImpl implements OrderService {

    private final OrderMapper orderMapper;

    @Autowired
    public OrderServiceImpl(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    @Override
    public SaResult getOrderDetails(OrderQo orderQo) {
        Object orderDetailsWithCarInfo1 = StpUtil.getSession().get("orderDetailsWithCarInfo");
        try {
            if (orderDetailsWithCarInfo1==null){
                OrderDetailsVO orderDetailsWithCarInfo = orderMapper.getOrderDetailsWithCarInfo(orderQo);
                StpUtil.getSession().set("orderDetailsWithCarInfo", orderDetailsWithCarInfo);

                return SaResult.ok().setData(StpUtil.getSession().get("orderDetailsWithCarInfo"));
            }else {
                return SaResult.ok().setData(StpUtil.getSession().get("orderDetailsWithCarInfo"));
            }
        }catch (Exception e){
//            e.printStackTrace();
            return SaResult.error("数据有误请联系公司");
        }
    }


}
